// package com.example.onlinemonitoring.comCenter;

// import com.example.onlinemonitoring.Util.CRC16;
// import com.example.onlinemonitoring.Util.CommPortManager;
// import com.example.onlinemonitoring.Util.HexUtil;
// import com.example.onlinemonitoring.model.Appdevice;
// import com.example.onlinemonitoring.model.Gispdhistory;
// import com.example.onlinemonitoring.model.Gispdsensor;
// import com.example.onlinemonitoring.model.Scpdhistory;
// import com.example.onlinemonitoring.model.Scpdsensor;
// import com.example.onlinemonitoring.model.Sctmnhistory;
// import com.example.onlinemonitoring.model.Sctmnsensor;
// import org.springframework.context.annotation.Scope;

// import com.example.onlinemonitoring.serviceImpl.GispdsensorServiceImpl;
// import com.example.onlinemonitoring.serviceImpl.ScpdsensorServiceImpl;
// import com.example.onlinemonitoring.serviceImpl.SctmnsensorServiceImpl;
// import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.scheduling.annotation.Async;
// import org.springframework.stereotype.Service;
// import org.springframework.transaction.annotation.Transactional;

// import java.text.ParseException;
// import java.util.Date;
// import java.util.List;
// import java.util.concurrent.TimeUnit;

// /**
//  * 开关柜测温和开关柜局放（济钢）
//  */
// @Service("sctmCom")
// @Scope("prototype")
// public class SctmCom extends CommPortManager {
//     @Autowired
//     private SctmnsensorServiceImpl sctmnserviceimpl;
//     String recvmsg[] = new String[256];
//     int cmdlen = 0;

//     public void ClearCache() {
//         for (int i = 0; i < recvmsg.length; i++) {
//             recvmsg[i] = "";
//         }
//     }

//     @Override
//     public void receiveDatas(String str) {
//         setText(str);
//         if (!str.substring(2, 4).equals("03") || currcmd >= recvmsg.length) {
//             return;
//         }
//         String addrstr = str.substring(0, 2);
//         Integer addrint = parsePHex4(addrstr);
//         reSend[addrint] = 0;
//         recvmsg[currcmd] = str.substring(6, str.length() - 4);
//         boolean flag = false;
//         for (int i = 0; i < cmdlen; i++) {
//             if (recvmsg[i].isEmpty()) {
//                 flag = true;
//             }
//         }
//         if (!flag) {
//             String msg = "";
//             String vmsg = "";
//             for (int i = 0; i < cmdlen / 2; i++) {
//                 msg += recvmsg[i];
//             }
//             for (int i = cmdlen / 2; i < cmdlen; i++) {
//                 vmsg += recvmsg[1];
//             }

//             Sctmnsensor sctmn = new Sctmnsensor();
//             sctmn.setStationid(ad.getStationid());
//             sctmn.setDevicegroup(ad.getDevicegroup());
//             sctmn.setDeviceaddr(addrint);
//             List<Sctmnsensor> list = sctmnserviceimpl.getLists(sctmn);
//             int index = 0, vindex = 0;
//             for (Sctmnsensor ss : list) {
//                 sctmn.setPointaddr(ss.getPointaddr());
//                 try {
//                     // 温度数据
//                     sctmn.setLasta(parseHex4(msg.substring(index, index + 4)) * 0.1f);
//                     index += 4;
//                     sctmn.setLastb(parseHex4(msg.substring(index, index + 4)) * 0.1f);
//                     index += 4;
//                     sctmn.setLastc(parseHex4(msg.substring(index, index + 4)) * 0.1f);
//                     index += 4;
//                     // 电压数据
//                     sctmn.setLastabv(parsePHex4(vmsg.substring(vindex, vindex + 4)) * 1f);
//                     vindex += 4;
//                     sctmn.setLastbbv(parsePHex4(vmsg.substring(vindex, vindex + 4)) * 1f);
//                     vindex += 4;
//                     sctmn.setLastcbv(parsePHex4(vmsg.substring(vindex, vindex + 4)) * 1f);
//                     vindex += 4;
//                 } catch (Exception e) {
//                     System.out.println(e.toString());
//                     // TODO: handle exception
//                 }

//                 sctmn.setLastaalarmstatus(GetAlarmStatus(isnull(sctmn.getLasta()),
//                         isnull(ss.getAalarmvalue()),
//                         isnull(ss.getAalarmrelievevalue()),
//                         isnull(ss.getAwarnvalue()),
//                         isnull(ss.getAwarnrelievevalue()),
//                         isnull(ss.getLastaalarmstatus()), true, ss.getPointname() + "A相温度", ss.getDevicegroup(),
//                         ss.getDeviceaddr(), ss.getPointname(), ss.getPointaddr()));

//                 sctmn.setLastbalarmstatus(GetAlarmStatus(isnull(sctmn.getLastb()),
//                         isnull(ss.getBalarmvalue()),
//                         isnull(ss.getBalarmrelievevalue()),
//                         isnull(ss.getBwarnvalue()),
//                         isnull(ss.getBwarnrelievevalue()),
//                         isnull(ss.getLastbalarmstatus()), true, ss.getPointname() + "B相温度", ss.getDevicegroup(),
//                         ss.getDeviceaddr(), ss.getPointname(), ss.getPointaddr()));

//                 sctmn.setLastcalarmstatus(GetAlarmStatus(isnull(sctmn.getLastc()),
//                         isnull(ss.getCalarmvalue()),
//                         isnull(ss.getCalarmrelievevalue()),
//                         isnull(ss.getCwarnvalue()),
//                         isnull(ss.getCwarnrelievevalue()),
//                         isnull(ss.getLastcalarmstatus()), true, ss.getPointname() + "C相温度", ss.getDevicegroup(),
//                         ss.getDeviceaddr(), ss.getPointname(), ss.getPointaddr()));

//                 sctmn.setLastabvalarmstatus(GetAlarmStatus(isnull(sctmn.getLastabv()),
//                         isnull(ss.getBvalarmvalue()),
//                         isnull(ss.getBvalarmrelievevalue()),
//                         isnull(ss.getBvwarnvalue()),
//                         isnull(ss.getBvwarnrelievevalue()),
//                         isnull(ss.getLastabvalarmstatus()), false, ss.getPointname() + "A相电池电压", ss.getDevicegroup(),
//                         ss.getDeviceaddr(), ss.getPointname(), ss.getPointaddr()));

//                 sctmn.setLastbbvalarmstatus(GetAlarmStatus(isnull(sctmn.getLastbbv()),
//                         isnull(ss.getBvalarmvalue()),
//                         isnull(ss.getBvalarmrelievevalue()),
//                         isnull(ss.getBvwarnvalue()),
//                         isnull(ss.getBvwarnrelievevalue()),
//                         isnull(ss.getLastbbvalarmstatus()), false, ss.getPointname() + "B相电池电压", ss.getDevicegroup(),
//                         ss.getDeviceaddr(), ss.getPointname(), ss.getPointaddr()));

//                 sctmn.setLastcbvalarmstatus(GetAlarmStatus(isnull(sctmn.getLastcbv()),
//                         isnull(ss.getBvalarmvalue()),
//                         isnull(ss.getBvalarmrelievevalue()),
//                         isnull(ss.getBvwarnvalue()),
//                         isnull(ss.getBvwarnrelievevalue()),
//                         isnull(ss.getLastcbvalarmstatus()), false, ss.getPointname() + "C相电池电压", ss.getDevicegroup(),
//                         ss.getDeviceaddr(), ss.getPointname(), ss.getPointaddr()));
//                 String alarmMessage = "";
//                 alarmMessage += GetAlarmMessage(isnull(sctmn.getLastaalarmstatus()), ss.getPointname() + "A相温度");
//                 alarmMessage += GetAlarmMessage(isnull(sctmn.getLastbalarmstatus()), ss.getPointname() + "B相温度");
//                 alarmMessage += GetAlarmMessage(isnull(sctmn.getLastcalarmstatus()), ss.getPointname() + "C相温度");
//                 alarmMessage += GetAlarmMessage(isnull(sctmn.getLastabvalarmstatus()), ss.getPointname() + "A相电池电压");
//                 alarmMessage += GetAlarmMessage(isnull(sctmn.getLastbbvalarmstatus()), ss.getPointname() + "B相电池电压");
//                 alarmMessage += GetAlarmMessage(isnull(sctmn.getLastcbvalarmstatus()), ss.getPointname() + "C相电池电压");
//                 sctmn.setLastalarmlevel(HexUtil.MAX(new int[] {
//                         isnull(sctmn.getLastaalarmstatus()),
//                         isnull(sctmn.getLastbalarmstatus()),
//                         isnull(sctmn.getLastcalarmstatus()),
//                         isnull(sctmn.getLastabvalarmstatus()),
//                         isnull(sctmn.getLastbbvalarmstatus()),
//                         isnull(sctmn.getLastcbvalarmstatus()) }));

//                 sctmn.setLastalarmmessage(alarmMessage);
//                 sctmn.setLastcommunicationstatus(0);
//                 sctmn.setLastdatatime(new Date());
//                 sctmn.setLasthisdatatime(addHistory(ss));
//                 sctmnserviceimpl.Update(sctmn, false);
//             }
//             addrindex++;
//             setText("开关柜测温数据解析完毕！");
//         }
//     }

//     private Date addHistory(Sctmnsensor sensor) {
//         if (sensor != null) {
//             if (sensor.getLasthisdatatime() == null) {
//                 add(sensor);
//                 return new Date();
//             } else {
//                 long lasttime = 0;
//                 long nowtime = 0;
//                 try {
//                     lasttime = HexUtil.todate(sensor.getLasthisdatatime()).getTime();
//                     nowtime = HexUtil.todate(new Date()).getTime();
//                 } catch (ParseException e) {
//                     e.printStackTrace();
//                 }
//                 int timersp = 60000;
//                 if (sensor.getLastalarmlevel() != 0) {
//                     timersp = ad.getHisalarmtimersp() * 1000;
//                 } else {
//                     timersp = ad.getHistimersp() * 1000;
//                 }
//                 if (lasttime + timersp < nowtime) {
//                     add(sensor);
//                     return new Date();
//                 }
//             }
//         }
//         return null;
//     }

//     private void add(Sctmnsensor sensor) {
//         Sctmnhistory his = new Sctmnhistory();
//         his.setStationid(sensor.getStationid());
//         his.setDevicegroup(sensor.getDevicegroup());
//         his.setDeviceaddr(sensor.getDeviceaddr());
//         his.setPointaddr(sensor.getPointaddr());
//         his.setAddrname(sensor.getAddrname());
//         his.setPointname(sensor.getPointname());
//         his.setDatatime(sensor.getLastdatatime());
//         his.setA(sensor.getLasta());
//         his.setB(sensor.getLastb());
//         his.setC(sensor.getLastc());
//         his.setAlarmlevel(sensor.getLastalarmlevel());
//         his.setAlarmmessage(sensor.getLastalarmmessage());
//         his.setAalarmstatus(sensor.getLastaalarmstatus());
//         his.setBalarmstatus(sensor.getLastbalarmstatus());
//         his.setCalarmstatus(sensor.getLastcalarmstatus());
//         his.setMemo(sensor.getMemo());
//         his.setInuse(sensor.getInuse());
//         his.setStyle(sensor.getStyle());
//         his.setAbv(sensor.getLastabv());
//         his.setBbv(sensor.getLastbbv());
//         his.setCbv(sensor.getLastcbv());
//         his.setAbvalarmstatus(sensor.getLastabvalarmstatus());
//         his.setBbvalarmstatus(sensor.getLastbbvalarmstatus());
//         his.setCbvalarmstatus(sensor.getLastcbvalarmstatus());
//         sctmnserviceimpl.Add(his);
//     }

//     @Async("threadPool")
//     public void startSendThread(Appdevice Appdevice) throws Exception {
//         String cmd[] = Appdevice.getCmd().split(",");
//         cmdlen = cmd.length;
//         // cmd[0] = "%s0305DD0009";// 温度
//         // cmd[1] = "%s0309C50009";// 电压
//         checkType = "crc16";
//         issend.put(Thread.currentThread().getId(), true);
//         String cstr = "";
//         int timeoutsp = (int) Math.round(Appdevice.getTimeoutsp() * 1000);
//         timersp = (int) Math.round(Appdevice.getTimersp() * 1000);
//         while (issend.get(Thread.currentThread().getId()) != null) {
//             rlock.lock();
//             try {
//                 if (isrun) {
//                     if (addrindex > Appdevice.getAddrmax() || addrindex < Appdevice.getAddrmin())
//                         addrindex = Appdevice.getAddrmin();
//                     currcmd = 0;
//                     for (int i = 0; i < cmd.length; i++) {
//                         if (currcmd == 0) {
//                             ClearCache();
//                         }
//                         cstr = String.format(cmd[currcmd], String.format("%02X", addrindex));
//                         cstr = cstr + CRC16.calcCrc16(cstr);
//                         Send(cstr);
//                         sendCondition.await(timeoutsp, TimeUnit.MILLISECONDS);
//                         currcmd++;
//                     }

//                     if (reSend[addrindex] > 3) {
//                         sctmnserviceimpl.UpdateStatus(ad, addrindex, 1);
//                         reSend[addrindex] = 0;
//                         addrindex++;
//                     }
//                     reSend[addrindex]++;
//                 } else if (rescode != 0) {
//                     setText(resmsg[rescode]);
//                 }
//             } catch (Exception e) {
//                 // TODO: handle exception
//             } finally {
//                 rlock.unlock();
//             }
//         }
//     }
// }

package com.example.onlinemonitoring.comCenter;

import com.example.onlinemonitoring.Util.CRC16;
import com.example.onlinemonitoring.Util.CommPortManager;
import com.example.onlinemonitoring.Util.HexUtil;
import com.example.onlinemonitoring.model.Appdevice;
import com.example.onlinemonitoring.model.Sctmhistory;
import com.example.onlinemonitoring.model.Sctmsensor;
import com.example.onlinemonitoring.model.common.sensor;
import com.example.onlinemonitoring.serviceImpl.SctmsensorServiceImpl;
import java.text.ParseException;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service("sctmCom")
@Scope("prototype")
public class SctmCom extends CommPortManager {
        public int nextstep;

        public int splitstep = 0;

        @Autowired
        private SctmsensorServiceImpl sctmserviceimpl;

        public void receiveData(String str) {
                setText(str);
                if (!str.substring(2, 4).equals("03"))
                        return;
                String addrstr = str.substring(0, 2);
                Integer addrint = Integer.valueOf(parseHex4(addrstr));
                setText("数据解析中...");
                int start = 0;
                int end = 0;
                this.reSend[addrint.intValue()] = 0;
                if (this.splitstep == 1) {
                        Integer integer = this.addrindex;
                        this.addrindex = Integer.valueOf(this.addrindex.intValue() + 1);
                        start = 1;
                        end = 9;
                } else if (this.splitstep == 2) {
                        start = 10;
                        end = 17;
                }
                if (this.nextstep == 1) {
                        for (int i = start; i <= end; i++) {
                                Sctmsensor sctm = new Sctmsensor();
                                sctm.setStationid(this.ad.getStationid());
                                sctm.setDevicegroup(this.ad.getDevicegroup());
                                sctm.setDeviceaddr(addrint);
                                sctm.setPointaddr(Integer.valueOf(i));
                                sctm.setLastacable(
                                                Float.valueOf(parseHex4(str.substring((i - start) * 36 + 6,
                                                                (i - start) * 36 + 10)) * 0.1F));
                                sctm.setLastbcable(
                                                Float.valueOf(parseHex4(str.substring((i - start) * 36 + 10,
                                                                (i - start) * 36 + 14)) * 0.1F));
                                sctm.setLastccable(
                                                Float.valueOf(parseHex4(str.substring((i - start) * 36 + 14,
                                                                (i - start) * 36 + 18)) * 0.1F));
                                sctm.setLastaupcontact(
                                                Float.valueOf(parseHex4(str.substring((i - start) * 36 + 18,
                                                                (i - start) * 36 + 22)) * 0.1F));
                                sctm.setLastbupcontact(
                                                Float.valueOf(parseHex4(str.substring((i - start) * 36 + 22,
                                                                (i - start) * 36 + 26)) * 0.1F));
                                sctm.setLastcupcontact(
                                                Float.valueOf(parseHex4(str.substring((i - start) * 36 + 26,
                                                                (i - start) * 36 + 30)) * 0.1F));
                                sctm.setLastalowcontact(
                                                Float.valueOf(parseHex4(str.substring((i - start) * 36 + 30,
                                                                (i - start) * 36 + 34)) * 0.1F));
                                sctm.setLastblowcontact(
                                                Float.valueOf(parseHex4(str.substring((i - start) * 36 + 34,
                                                                (i - start) * 36 + 38)) * 0.1F));
                                sctm.setLastclowcontact(
                                                Float.valueOf(parseHex4(str.substring((i - start) * 36 + 38,
                                                                (i - start) * 36 + 42)) * 0.1F));
                                if (validate(sctm.getLastacable().floatValue())
                                                || validate(sctm.getLastbcable().floatValue())
                                                || validate(sctm.getLastccable().floatValue()) ||
                                                validate(sctm.getLastaupcontact().floatValue())
                                                || validate(sctm.getLastbupcontact().floatValue()) ||
                                                validate(sctm.getLastcupcontact().floatValue()) ||
                                                validate(sctm.getLastalowcontact().floatValue())
                                                || validate(sctm.getLastblowcontact().floatValue()) ||
                                                validate(sctm.getLastclowcontact().floatValue()))
                                        return;
                                Sctmsensor alarm = (Sctmsensor) sctmserviceimpl.getModel(sctm);
                                if (alarm != null) {
                                        sctm.setLastacablealarmstatus(Integer.valueOf(GetAlarmStatus(
                                                        isnull(sctm.getLastacable()).floatValue(),
                                                        isnull(alarm.getAcablealarmvalue()).floatValue(),
                                                        isnull(alarm.getAcablealarmrelievevalue()).floatValue(),
                                                        isnull(alarm.getAcablewarnvalue()).floatValue(),
                                                        isnull(alarm.getAcablewarnrelievevalue()).floatValue(),
                                                        isnull(alarm.getLastacablealarmstatus()).intValue(),
                                                        Boolean.valueOf(true), "A相电缆温度",
                                                        alarm.getDevicegroup().intValue(), addrint.intValue(),
                                                        alarm.getPointname(), i)));
                                        sctm.setLastbcablealarmstatus(Integer.valueOf(GetAlarmStatus(
                                                        isnull(sctm.getLastbcable()).floatValue(),
                                                        isnull(alarm.getBcablealarmvalue()).floatValue(),
                                                        isnull(alarm.getBcablealarmrelievevalue()).floatValue(),
                                                        isnull(alarm.getBcablewarnvalue()).floatValue(),
                                                        isnull(alarm.getBcablewarnrelievevalue()).floatValue(),
                                                        isnull(alarm.getLastbcablealarmstatus()).intValue(),
                                                        Boolean.valueOf(true), "B相电缆温度",
                                                        alarm.getDevicegroup().intValue(), addrint.intValue(),
                                                        alarm.getPointname(), i)));
                                        sctm.setLastccablealarmstatus(Integer.valueOf(GetAlarmStatus(
                                                        isnull(sctm.getLastccable()).floatValue(),
                                                        isnull(alarm.getCcablealarmvalue()).floatValue(),
                                                        isnull(alarm.getCcablealarmrelievevalue()).floatValue(),
                                                        isnull(alarm.getCcablewarnvalue()).floatValue(),
                                                        isnull(alarm.getCcablewarnrelievevalue()).floatValue(),
                                                        isnull(alarm.getLastccablealarmstatus()).intValue(),
                                                        Boolean.valueOf(true), "C相电缆温度",
                                                        alarm.getDevicegroup().intValue(), addrint.intValue(),
                                                        alarm.getPointname(), i)));
                                        sctm.setLastaupcontactalarmstatus(Integer.valueOf(GetAlarmStatus(
                                                        HexUtil.isnull(sctm.getLastaupcontact()).floatValue(),
                                                        HexUtil.isnull(alarm.getAupcontactalarmvalue()).floatValue(),
                                                        HexUtil.isnull(alarm.getAupcontactalarmrelievevalue())
                                                                        .floatValue(),
                                                        HexUtil.isnull(alarm.getAupcontactwarnvalue()).floatValue(),
                                                        HexUtil.isnull(alarm.getAupcontactwarnrelievevalue())
                                                                        .floatValue(),
                                                        HexUtil.isnull(alarm.getLastaupcontactalarmstatus()).intValue(),
                                                        Boolean.valueOf(true),
                                                        "上触头A相温度", alarm.getDevicegroup().intValue(),
                                                        addrint.intValue(), alarm
                                                                        .getPointname(),
                                                        i)));
                                        sctm.setLastbupcontactalarmstatus(Integer.valueOf(GetAlarmStatus(
                                                        HexUtil.isnull(sctm.getLastbupcontact()).floatValue(),
                                                        HexUtil.isnull(alarm.getBupcontactalarmvalue()).floatValue(),
                                                        HexUtil.isnull(alarm.getBupcontactalarmrelievevalue())
                                                                        .floatValue(),
                                                        HexUtil.isnull(alarm.getBupcontactwarnvalue()).floatValue(),
                                                        HexUtil.isnull(alarm.getBupcontactwarnrelievevalue())
                                                                        .floatValue(),
                                                        HexUtil.isnull(alarm.getLastbupcontactalarmstatus()).intValue(),
                                                        Boolean.valueOf(true),
                                                        "上触头B相温度", alarm.getDevicegroup().intValue(),
                                                        addrint.intValue(), alarm
                                                                        .getPointname(),
                                                        i)));
                                        sctm.setLastcupcontactalarmstatus(Integer.valueOf(GetAlarmStatus(
                                                        HexUtil.isnull(sctm.getLastcupcontact()).floatValue(),
                                                        HexUtil.isnull(alarm.getCupcontactalarmvalue()).floatValue(),
                                                        HexUtil.isnull(alarm.getCupcontactalarmrelievevalue())
                                                                        .floatValue(),
                                                        HexUtil.isnull(alarm.getCupcontactwarnvalue()).floatValue(),
                                                        HexUtil.isnull(alarm.getCupcontactwarnrelievevalue())
                                                                        .floatValue(),
                                                        HexUtil.isnull(alarm.getLastcupcontactalarmstatus()).intValue(),
                                                        Boolean.valueOf(true),
                                                        "上触头C相温度", alarm.getDevicegroup().intValue(),
                                                        addrint.intValue(), alarm
                                                                        .getPointname(),
                                                        i)));
                                        sctm.setLastalowcontactalarmstatus(Integer.valueOf(GetAlarmStatus(
                                                        HexUtil.isnull(sctm.getLastalowcontact()).floatValue(),
                                                        HexUtil.isnull(alarm.getAlowcontactalarmvalue()).floatValue(),
                                                        HexUtil.isnull(alarm.getAlowcontactalarmrelievevalue())
                                                                        .floatValue(),
                                                        HexUtil.isnull(alarm.getAlowcontactwarnvalue()).floatValue(),
                                                        HexUtil.isnull(alarm.getAlowcontactwarnrelievevalue())
                                                                        .floatValue(),
                                                        HexUtil.isnull(alarm.getLastalowcontactalarmstatus())
                                                                        .intValue(),
                                                        Boolean.valueOf(true),
                                                        "下触头A相温度", alarm.getDevicegroup().intValue(),
                                                        addrint.intValue(), alarm
                                                                        .getPointname(),
                                                        i)));
                                        sctm.setLastblowcontactalarmstatus(Integer.valueOf(GetAlarmStatus(
                                                        HexUtil.isnull(sctm.getLastblowcontact()).floatValue(),
                                                        HexUtil.isnull(alarm.getBlowcontactalarmvalue()).floatValue(),
                                                        HexUtil.isnull(alarm.getBlowcontactalarmrelievevalue())
                                                                        .floatValue(),
                                                        HexUtil.isnull(alarm.getBlowcontactwarnvalue()).floatValue(),
                                                        HexUtil.isnull(alarm.getBlowcontactwarnrelievevalue())
                                                                        .floatValue(),
                                                        HexUtil.isnull(alarm.getLastblowcontactalarmstatus())
                                                                        .intValue(),
                                                        Boolean.valueOf(true),
                                                        "下触头B相温度", alarm.getDevicegroup().intValue(),
                                                        addrint.intValue(), alarm
                                                                        .getPointname(),
                                                        i)));
                                        sctm.setLastclowcontactalarmstatus(Integer.valueOf(GetAlarmStatus(
                                                        HexUtil.isnull(sctm.getLastclowcontact()).floatValue(),
                                                        HexUtil.isnull(alarm.getClowcontactalarmvalue()).floatValue(),
                                                        HexUtil.isnull(alarm.getClowcontactalarmrelievevalue())
                                                                        .floatValue(),
                                                        HexUtil.isnull(alarm.getClowcontactwarnvalue()).floatValue(),
                                                        HexUtil.isnull(alarm.getClowcontactwarnrelievevalue())
                                                                        .floatValue(),
                                                        HexUtil.isnull(alarm.getLastclowcontactalarmstatus())
                                                                        .intValue(),
                                                        Boolean.valueOf(true),
                                                        "下触头C相温度", alarm.getDevicegroup().intValue(),
                                                        addrint.intValue(), alarm
                                                                        .getPointname(),
                                                        i)));
                                        sctm.setLastdatatimexj(new Date());
                                        sctm.setLastdatatime(new Date());
                                        String alarmMessage = "";
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        alarmMessage = alarmMessage + alarmMessage;
                                        sctm.setLastalarmlevel(Integer.valueOf(HexUtil.MAX(new int[] {
                                                        isnull(alarm.getLastaupcontactalarmstatus()).intValue(),
                                                        isnull(alarm.getLastbupcontactalarmstatus()).intValue(),
                                                        isnull(alarm.getLastcupcontactalarmstatus()).intValue(),
                                                        isnull(alarm.getLastalowcontactalarmstatus()).intValue(),
                                                        isnull(alarm.getLastblowcontactalarmstatus()).intValue(),
                                                        isnull(alarm.getLastclowcontactalarmstatus()).intValue(),
                                                        isnull(alarm.getLastacablealarmstatus()).intValue(),
                                                        isnull(alarm.getLastbcablealarmstatus()).intValue(),
                                                        isnull(alarm.getLastccablealarmstatus()).intValue(),
                                                        isnull(alarm.getLastbatteryvoltage1alarmstatus()).intValue(),
                                                        isnull(alarm.getLastbatteryvoltage2alarmstatus()).intValue(),
                                                        isnull(alarm.getLastbatteryvoltage3alarmstatus()).intValue(),
                                                        isnull(alarm.getLastbatteryvoltage4alarmstatus()).intValue(),
                                                        isnull(alarm.getLastbatteryvoltage5alarmstatus()).intValue(),
                                                        isnull(alarm.getLastbatteryvoltage6alarmstatus()).intValue(),
                                                        isnull(alarm.getLastbatteryvoltage7alarmstatus()).intValue(),
                                                        isnull(alarm.getLastbatteryvoltage8alarmstatus()).intValue(),
                                                        isnull(alarm.getLastbatteryvoltage9alarmstatus())
                                                                        .intValue() })));
                                        sctm.setLastalarmmessage(alarmMessage);
                                        sctm.setLastcommunicationstatus(Integer.valueOf(0));
                                        sctm.setLasthisdatatime(
                                                        addHistory((Sctmsensor) sctmserviceimpl.getModel(sctm)));
                                        sctmserviceimpl.Update(sctm, false);
                                }
                        }
                        if (this.splitstep == 1) {
                                String cstr = String.format("%s03",
                                                new Object[] { HexUtil.intToHexString(addrint.intValue(), 1) });
                                cstr = cstr + "062E";
                                cstr = cstr + "0048";
                                cstr = cstr + CRC16.calcCrc16(cstr);
                                try {
                                        setText("请求第二包数据" + cstr);
                                        Send(cstr);
                                } catch (Exception EX) {
                                        setText(EX.toString());
                                }
                                this.splitstep = 2;
                        }
                } else {
                        for (int i = start; i <= end; i++) {
                                Sctmsensor sctm = new Sctmsensor();
                                sctm.setStationid(this.ad.getStationid());
                                sctm.setDevicegroup(this.ad.getDevicegroup());
                                sctm.setDeviceaddr(addrint);
                                sctm.setPointaddr(Integer.valueOf(i));
                                sctm.setLastbatteryvoltage1(
                                                Integer.valueOf(parseHex4(str.substring((i - start) * 36 + 6,
                                                                (i - start) * 36 + 10))));
                                sctm.setLastbatteryvoltage2(
                                                Integer.valueOf(parseHex4(str.substring((i - start) * 36 + 10,
                                                                (i - start) * 36 + 14))));
                                sctm.setLastbatteryvoltage3(
                                                Integer.valueOf(parseHex4(str.substring((i - start) * 36 + 14,
                                                                (i - start) * 36 + 18))));
                                sctm.setLastbatteryvoltage4(
                                                Integer.valueOf(parseHex4(str.substring((i - start) * 36 + 18,
                                                                (i - start) * 36 + 22))));
                                sctm.setLastbatteryvoltage5(
                                                Integer.valueOf(parseHex4(str.substring((i - start) * 36 + 22,
                                                                (i - start) * 36 + 26))));
                                sctm.setLastbatteryvoltage6(
                                                Integer.valueOf(parseHex4(str.substring((i - start) * 36 + 26,
                                                                (i - start) * 36 + 30))));
                                sctm.setLastbatteryvoltage7(
                                                Integer.valueOf(parseHex4(str.substring((i - start) * 36 + 30,
                                                                (i - start) * 36 + 34))));
                                sctm.setLastbatteryvoltage8(
                                                Integer.valueOf(parseHex4(str.substring((i - start) * 36 + 34,
                                                                (i - start) * 36 + 38))));
                                sctm.setLastbatteryvoltage9(
                                                Integer.valueOf(parseHex4(str.substring((i - start) * 36 + 38,
                                                                (i - start) * 36 + 42))));
                                if (sctm.getLastbatteryvoltage1().intValue() != 0
                                                || sctm.getLastbatteryvoltage2().intValue() != 0
                                                || sctm
                                                                .getLastbatteryvoltage3().intValue() != 0
                                                || sctm
                                                                .getLastbatteryvoltage4().intValue() != 0
                                                || sctm.getLastbatteryvoltage5().intValue() != 0 || sctm
                                                                .getLastbatteryvoltage6().intValue() != 0
                                                || sctm
                                                                .getLastbatteryvoltage7().intValue() != 0
                                                || sctm.getLastbatteryvoltage8().intValue() != 0 || sctm
                                                                .getLastbatteryvoltage9().intValue() != 0) {
                                        Sctmsensor alarm = (Sctmsensor) sctmserviceimpl.getModel(sctm);
                                        if (alarm != null) {
                                                sctm.setLastbatteryvoltage1alarmstatus(
                                                                Integer.valueOf(GetAlarmStatus(HexUtil
                                                                                .isnull(sctm.getLastbatteryvoltage1())
                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getLastbatteryvoltage7alarmstatus())
                                                                                                .intValue(),
                                                                                Boolean.valueOf(false), "上触头A相电池电压",
                                                                                alarm.getDevicegroup().intValue(),
                                                                                addrint.intValue(), alarm
                                                                                                .getPointname(),
                                                                                i)));
                                                sctm.setLastbatteryvoltage2alarmstatus(
                                                                Integer.valueOf(GetAlarmStatus(HexUtil
                                                                                .isnull(sctm.getLastbatteryvoltage2())
                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getLastbatteryvoltage8alarmstatus())
                                                                                                .intValue(),
                                                                                Boolean.valueOf(false), "上触头B相电池电压",
                                                                                alarm.getDevicegroup().intValue(),
                                                                                addrint.intValue(), alarm
                                                                                                .getPointname(),
                                                                                i)));
                                                sctm.setLastbatteryvoltage3alarmstatus(
                                                                Integer.valueOf(GetAlarmStatus(HexUtil
                                                                                .isnull(sctm.getLastbatteryvoltage3())
                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getLastbatteryvoltage9alarmstatus())
                                                                                                .intValue(),
                                                                                Boolean.valueOf(false), "上触头C相电池电压",
                                                                                alarm.getDevicegroup().intValue(),
                                                                                addrint.intValue(), alarm
                                                                                                .getPointname(),
                                                                                i)));
                                                sctm.setLastbatteryvoltage4alarmstatus(
                                                                Integer.valueOf(GetAlarmStatus(HexUtil
                                                                                .isnull(sctm.getLastbatteryvoltage4())
                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getLastbatteryvoltage7alarmstatus())
                                                                                                .intValue(),
                                                                                Boolean.valueOf(false), "下触头A相电池电压",
                                                                                alarm.getDevicegroup().intValue(),
                                                                                addrint.intValue(), alarm
                                                                                                .getPointname(),
                                                                                i)));
                                                sctm.setLastbatteryvoltage5alarmstatus(
                                                                Integer.valueOf(GetAlarmStatus(HexUtil
                                                                                .isnull(sctm.getLastbatteryvoltage5())
                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getLastbatteryvoltage8alarmstatus())
                                                                                                .intValue(),
                                                                                Boolean.valueOf(false), "下触头B相电池电压",
                                                                                alarm.getDevicegroup().intValue(),
                                                                                addrint.intValue(), alarm
                                                                                                .getPointname(),
                                                                                i)));
                                                sctm.setLastbatteryvoltage6alarmstatus(
                                                                Integer.valueOf(GetAlarmStatus(HexUtil
                                                                                .isnull(sctm.getLastbatteryvoltage6())
                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getLastbatteryvoltage9alarmstatus())
                                                                                                .intValue(),
                                                                                Boolean.valueOf(false), "下触头C相电池电压",
                                                                                alarm.getDevicegroup().intValue(),
                                                                                addrint.intValue(), alarm
                                                                                                .getPointname(),
                                                                                i)));
                                                sctm.setLastbatteryvoltage7alarmstatus(
                                                                Integer.valueOf(GetAlarmStatus(HexUtil
                                                                                .isnull(sctm.getLastbatteryvoltage7())
                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getLastbatteryvoltage7alarmstatus())
                                                                                                .intValue(),
                                                                                Boolean.valueOf(false), "A相电缆电池电压",
                                                                                alarm.getDevicegroup().intValue(),
                                                                                addrint.intValue(), alarm
                                                                                                .getPointname(),
                                                                                i)));
                                                sctm.setLastbatteryvoltage8alarmstatus(
                                                                Integer.valueOf(GetAlarmStatus(HexUtil
                                                                                .isnull(sctm.getLastbatteryvoltage8())
                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getLastbatteryvoltage8alarmstatus())
                                                                                                .intValue(),
                                                                                Boolean.valueOf(false), "B相电缆电池电压",
                                                                                alarm.getDevicegroup().intValue(),
                                                                                addrint.intValue(), alarm
                                                                                                .getPointname(),
                                                                                i)));
                                                sctm.setLastbatteryvoltage9alarmstatus(
                                                                Integer.valueOf(GetAlarmStatus(HexUtil
                                                                                .isnull(sctm.getLastbatteryvoltage9())
                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagealarmrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnvalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getBatteryvoltagewarnrelievevalue())
                                                                                                .intValue(),
                                                                                HexUtil.isnull(alarm
                                                                                                .getLastbatteryvoltage9alarmstatus())
                                                                                                .intValue(),
                                                                                Boolean.valueOf(false), "C相电缆电池电压",
                                                                                alarm.getDevicegroup().intValue(),
                                                                                addrint.intValue(), alarm
                                                                                                .getPointname(),
                                                                                i)));
                                                sctmserviceimpl.Update(sctm, false);
                                        }
                                }
                        }
                        if (this.splitstep == 1) {
                                String cstr = String.format("%s03",
                                                new Object[] { HexUtil.intToHexString(addrint.intValue(), 1) });
                                cstr = cstr + "0A16";
                                cstr = cstr + "0048";
                                cstr = cstr + CRC16.calcCrc16(cstr);
                                try {
                                        setText("请求第二包数据" + cstr);
                                        Send(cstr);
                                } catch (Exception EX) {
                                        setText(EX.toString());
                                }
                                this.splitstep = 2;
                        }
                }
                setText("数据解析完毕！");
        }

        private Date addHistory(Sctmsensor sensor) {
                if (sensor != null) {
                        if (sensor.getLasthisdatatime() == null) {
                                add(sensor);
                                return new Date();
                        }
                        long lasttime = 0L;
                        long nowtime = 0L;
                        try {
                                lasttime = HexUtil.todate(sensor.getLasthisdatatime()).getTime();
                                nowtime = HexUtil.todate(new Date()).getTime();
                        } catch (ParseException e) {
                                e.printStackTrace();
                        }
                        int timersp = 60000;
                        if (sensor.getLastalarmlevel().intValue() != 0) {
                                timersp = this.ad.getHisalarmtimersp().intValue() * 1000;
                        } else {
                                timersp = this.ad.getHistimersp().intValue() * 1000;
                        }
                        if (lasttime + timersp < nowtime) {
                                add(sensor);
                                return new Date();
                        }
                }
                return null;
        }

        private void add(Sctmsensor sensor) {
                Sctmhistory his = new Sctmhistory();
                his.setStationid(sensor.getStationid());
                his.setDevicegroup(sensor.getDevicegroup());
                his.setDeviceaddr(sensor.getDeviceaddr());
                his.setPointaddr(sensor.getPointaddr());
                his.setAddrname(sensor.getAddrname());
                his.setPointname(sensor.getPointname());
                his.setDatatime(sensor.getLastdatatime());
                his.setAupcontact(sensor.getLastaupcontact());
                his.setBupcontact(sensor.getLastbupcontact());
                his.setCupcontact(sensor.getLastcupcontact());
                his.setAlowcontact(sensor.getLastalowcontact());
                his.setBlowcontact(sensor.getLastblowcontact());
                his.setClowcontact(sensor.getLastclowcontact());
                his.setAcable(sensor.getLastacable());
                his.setBcable(sensor.getLastbcable());
                his.setCcable(sensor.getLastccable());
                his.setAlarmlevel(sensor.getLastalarmlevel());
                his.setAlarmmessage(sensor.getLastalarmmessage());
                his.setAupcontactalarmstatus(sensor.getLastaupcontactalarmstatus());
                his.setBupcontactalarmstatus(sensor.getLastbupcontactalarmstatus());
                his.setCupcontactalarmstatus(sensor.getLastcupcontactalarmstatus());
                his.setAlowcontactalarmstatus(sensor.getLastalowcontactalarmstatus());
                his.setBlowcontactalarmstatus(sensor.getLastblowcontactalarmstatus());
                his.setClowcontactalarmstatus(sensor.getLastclowcontactalarmstatus());
                his.setAcablealarmstatus(sensor.getLastacablealarmstatus());
                his.setBcablealarmstatus(sensor.getLastbcablealarmstatus());
                his.setCcablealarmstatus(sensor.getLastccablealarmstatus());
                his.setAspare(sensor.getLastaspare());
                his.setBspare(sensor.getLastbspare());
                his.setCspare(sensor.getLastcspare());
                his.setMemo(sensor.getMemo());
                his.setInuse(sensor.getInuse());
                his.setStyle(sensor.getStyle());
                his.setAsparealarmstatus(sensor.getLastasparealarmstatus());
                his.setBsparealarmstatus(sensor.getLastbsparealarmstatus());
                his.setCsparealarmstatus(sensor.getLastcsparealarmstatus());
                his.setBatteryvoltage1(sensor.getLastbatteryvoltage1());
                his.setBatteryvoltage2(sensor.getLastbatteryvoltage2());
                his.setBatteryvoltage3(sensor.getLastbatteryvoltage3());
                his.setBatteryvoltage4(sensor.getLastbatteryvoltage4());
                his.setBatteryvoltage5(sensor.getLastbatteryvoltage5());
                his.setBatteryvoltage6(sensor.getLastbatteryvoltage6());
                his.setBatteryvoltage7(sensor.getLastbatteryvoltage7());
                his.setBatteryvoltage8(sensor.getLastbatteryvoltage8());
                his.setBatteryvoltage9(sensor.getLastbatteryvoltage9());
                his.setBatteryvoltage1alarmstatus(sensor.getLastbatteryvoltage1alarmstatus());
                his.setBatteryvoltage2alarmstatus(sensor.getLastbatteryvoltage2alarmstatus());
                his.setBatteryvoltage3alarmstatus(sensor.getLastbatteryvoltage3alarmstatus());
                his.setBatteryvoltage4alarmstatus(sensor.getLastbatteryvoltage4alarmstatus());
                his.setBatteryvoltage5alarmstatus(sensor.getLastbatteryvoltage5alarmstatus());
                his.setBatteryvoltage6alarmstatus(sensor.getLastbatteryvoltage6alarmstatus());
                his.setBatteryvoltage7alarmstatus(sensor.getLastbatteryvoltage7alarmstatus());
                his.setBatteryvoltage8alarmstatus(sensor.getLastbatteryvoltage8alarmstatus());
                his.setBatteryvoltage9alarmstatus(sensor.getLastbatteryvoltage9alarmstatus());
                sctmserviceimpl.Add(his);
        }

        boolean validate(float value) {
                if (value > 1000.0F)
                        return true;
                return false;
        }

        @Async("threadPool")
        public void startSendThread(Appdevice appdevice) throws Exception {
                this.checkType = "crc16";
                this.issend.put(Long.valueOf(Thread.currentThread().getId()), Boolean.valueOf(true));
                String cstr = "";
                String cmdtype = "05DD";
                String nametype = "温度";
                int timersp = Math.round(appdevice.getTimersp().floatValue() * 1000.0F);
                while (this.issend.get(Long.valueOf(Thread.currentThread().getId())) != null) {
                        if (this.isrun) {
                                this.splitstep = 1;
                                if (this.addrindex.intValue() > appdevice.getAddrmax().intValue()
                                                || this.addrindex.intValue() < appdevice.getAddrmin().intValue()) {
                                        if (this.nextstep == 0) {
                                                setText("【=============准备开始温度数据采集=============】");
                                                cmdtype = "05DD";
                                                nametype = "温度";
                                                this.nextstep = 1;
                                        } else {
                                                setText("【=============准备开始电池电压数据采集=============】");
                                                cmdtype = "09C5";
                                                nametype = "电池电压";
                                                this.nextstep = 0;
                                        }
                                        setText("倒计时6秒...");
                                        Thread.sleep(1000L);
                                        setText("倒计时5秒...");
                                        Thread.sleep(1000L);
                                        setText("倒计时4秒...");
                                        Thread.sleep(1000L);
                                        setText("倒计时3秒...");
                                        Thread.sleep(1000L);
                                        setText("倒计时2秒...");
                                        Thread.sleep(1000L);
                                        setText("倒计时1秒...");
                                        Thread.sleep(1000L);
                                        this.addrindex = appdevice.getAddrmin();
                                }
                                cstr = String.format("%s03",
                                                new Object[] { HexUtil.intToHexString(this.addrindex.intValue(), 1) });
                                cstr = cstr + cmdtype;
                                cstr = cstr + "0069";
                                cstr = cstr + CRC16.calcCrc16(cstr);
                                try {
                                        Send(cstr);
                                } catch (Exception EX) {
                                        setText(EX.toString());
                                }
                                setText("向" + appdevice.getName() + "设备发送采集" + nametype + "指令" + cstr);
                                this.reSend[this.addrindex.intValue()] = this.reSend[this.addrindex.intValue()] + 1;
                                if (this.reSend[this.addrindex.intValue()] > 3) {
                                        sctmserviceimpl.UpdateStatus(this.ad, this.addrindex, 1);
                                        this.reSend[this.addrindex.intValue()] = 0;
                                        Integer integer = this.addrindex;
                                        this.addrindex = Integer.valueOf(this.addrindex.intValue() + 1);
                                }
                        } else if (this.rescode.intValue() != 0) {
                                setText(this.resmsg[this.rescode.intValue()]);
                        }
                        Thread.sleep(timersp);
                }
        }
}